package com.example.rdb.handle.etcd;

import com.example.rdb.conf.etcd.ReadEtcdUtil;
import com.example.rdb.conf.etcd.WriteEtcdUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.Set;

/**
 * @author XYC
 * @描述: TODO
 * @date 21.5.2817:32
 */
@Component
@Slf4j
public class EtcdMoveAll {

    private static String copyUrl="/apisix/";

    public void test() throws Exception {
        //将查询出来的应用Id和租户Id拼接在key上
        Map<String, String> etcdValueList = ReadEtcdUtil.getEtcdValueList(copyUrl);
        log.info("etcdValueList:"+etcdValueList.size());
        //遍历所有的key-value,将复制的数据添加到新的应用下
        Set<Map.Entry<String,String>> entrySet = etcdValueList.entrySet();
        for(Map.Entry<String,String> e:entrySet) {
            String key = e.getKey();
            String value = e.getValue();
            WriteEtcdUtil.putEtcdValueByKey(key, value);
        }
        Map<String, String> newList =WriteEtcdUtil.getEtcdValueList(copyUrl);
        if(newList.isEmpty()){
            log.info("etcd数据拷贝重写失败!");
        }
        log.info("etcd数据拷贝重写成功!");
    }

}
